package self.zhangkang.chart.view.avg.simlpe

import self.zhangkang.chart.view.IndexInfoHelper
import self.zhangkang.chart.view.avg.simlpe.index.SimpleAvgTurnVolume
import self.zhangkang.chart.view.pool.PathPool
import self.zhangkang.chart.view.pool.RectPool

/**
 * @author : Android-张康
 * created on: 2023/8/10 09:48
 * description:  简单分时图指标列表协助类
 */
class SimpleAvgIndexInfoHelper(
    private val pathPool: PathPool,
    private val rectPool: RectPool,
    private val simpleAvgViewColor: SimpleAvgViewColor,
    private val simpleAvgViewDimen: SimpleAvgViewDimen,
) : IndexInfoHelper<SimpleAvgChartIndex, SimpleAvgIndexInfo> {

    private val defaultList = listOf(
        SimpleAvgChartIndex.AvgChart,
        SimpleAvgChartIndex.AvgTurnVolume
    )

    /**
     * 创建指标
     *
     * @param chartIndex 指标信息
     *
     * @return 返回创建好指标信息
     */
    override fun createKLineIndexInfo(chartIndex: SimpleAvgChartIndex): SimpleAvgIndexInfo {
        return when (chartIndex) {
            SimpleAvgChartIndex.AvgChart -> {
                SimpleAvgChart(pathPool, rectPool, simpleAvgViewColor, simpleAvgViewDimen)
            }

            SimpleAvgChartIndex.AvgTurnVolume -> {
                SimpleAvgTurnVolume(pathPool, rectPool, simpleAvgViewColor, simpleAvgViewDimen)
            }
        }
    }

    /**
     * 是否可以切换
     *
     * @param currentIndex 当前指标
     *
     * @return true 可以切换下一个，false 不可以切换下一个
     */
    override fun canSwitch(currentIndex: SimpleAvgIndexInfo): Boolean {
        return false
    }

    /**
     * 下一个指标
     *
     * @param currentIndex 当前指标
     *
     * @return 返回下一个指标信息
     */
    override fun nextIndex(currentIndex: SimpleAvgIndexInfo): SimpleAvgIndexInfo {
        var findIndex = -1
        defaultList.forEachIndexed { index, kLineIndex ->
            if (kLineIndex == currentIndex.getIndexInfo()) {
                findIndex = index
                return@forEachIndexed
            }
        }
        if (findIndex == -1) {
            return currentIndex
        }
        if (findIndex >= defaultList.size - 1) {
            return createKLineIndexInfo(defaultList[0])
        }
        return createKLineIndexInfo(defaultList[findIndex + 1])
    }

}